<template>
  <div id="flowerActiveListSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="搜索" prop="name">
          <el-input
            clearable
            v-model="formInline.name"
            placeholder="请输入商品名称"
            size="small"
            class="numberInput"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品类别" prop="goodsType">
          <el-select v-model="formInline.goodsType" clearable placeholder="请选择">
            <el-option
              v-for="(item,index) in [
                { dictLabel: '全部', dictValue: '' },
                ...goodsTypes,
              ]"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品状态" prop="status">
          <el-select v-model="formInline.status" clearable placeholder="请选择">
            <el-option
              v-for="item in [
                { dictLabel: '全部', dictValue: '' },
                ...goodsStatus,
              ]"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset"> 重置 </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'goodsListSearch',
  msg: '商品列表管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function () {
        return {
          name: '', // 商品名称
          goodsType:'', // 商品类型
          status: '', // 商品状态
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: [],
        }
      },
    },
    streamStatus: {
      type: Array,
    },
    goodsTypes: {
      type: Array,
    },
    goodsStatus: {
      type: Array,
    },
  },
  data() {
    return {
      rules: {
        type: {},
        collegeId: {},
        title: {},
        createTime: { type: 'array' },
      },
      dialogVisible: false,
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true,
    },
  },
  methods: {
    changeVisible(bool, desc) {
      this.dialogVisible = bool
      if (desc) {
        this.$emit('toSearch')
      }
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    },
  },
}
</script>
